package com.crm.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import com.crm.interceptor.TokenInterceptor;
@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

	@Autowired
	private TokenInterceptor tokenInterceptor;
	
	 /**
     * 注册自定义拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor).addPathPatterns("/**").excludePathPatterns("/","/login","/sendMobileCode","/excel/**","/excel/**/**");
        super.addInterceptors(registry);
    }
    
    public void addCorsMappings(CorsRegistry registry) {
		//解决跨域
		registry.addMapping("/**").allowedOrigins("*").allowedMethods("GET", "POST", "PUT", "OPTIONS", "DELETE",
				"PATCH");
	}
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
		//指定静态资源
		registry.addResourceHandler("/**").addResourceLocations("classpath:/static/")
				.addResourceLocations("classpath:/templates/");
		super.addResourceHandlers(registry);
	}

	

}
